#
# @lc app=leetcode.cn id=1 lang=python
#
# [1] 两数之和
#

# @lc code=start
class Solution(object):
    def twoSum(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        """
        # 暴力法破解
        for i, num_x in enumerate(nums):
            for j, num_y in enumerate(nums):
                if i == j:
                    continue
                if num_x + num_y == target:
                    return [i, j]


class Solution(object):
    def twoSum(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        """
        # 双指针法
        new_nums = list()
        # 复制一份数据
        for i, num in enumerate(nums):
            new_nums.append((i, num))
        # 对数据进行排序
        new_nums.sort(key=lambda x:x[1])
        print(new_nums)
        # 双指针遍历
        i, j = 0, len(new_nums)-1
        while i < j:
            print(i, j)
            if new_nums[i][1] + new_nums[j][1] == target:
                return sorted([new_nums[i][0], new_nums[j][0]])
            elif new_nums[i][1] + new_nums[j][1] < target:
                i = i + 1
            else:
                j = j - 1
        
        return None
# @lc code=end

if __name__ == "__main__":
    solution = Solution()
    result = solution.twoSum([2, 3, 1, 8, 5], 6)
    print(result)

